﻿using Ext.Net;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class InfoQuery_Query_InStore : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ViewState_OrderSre = "CheckDate desc";
            BindCenterStore(Store_Rome, Request.QueryString["tabid"]);
            gridPanel_listdata.Reload();
        }
    }

    string _QueryString;
    private string GetQryString()
    {
        string result = " state=2 ";

        if (exttxtf_ExportBillNo.Text.Trim() != "")
            result += " and ExportBillNo like'%" + FilterSpecChar(exttxtf_ExportBillNo.Text.Trim()) + "%'";
        if (extdate_start.SelectedValue != null)
            result += " and InDate>='" + extdate_start.SelectedValue + "' ";
        if (extdate_end.SelectedValue != null)
            result += " and InDate<='" + extdate_end.SelectedValue + "' ";
        if (!string.IsNullOrEmpty(extcomb_STOREROOM_ID.SelectedItem.Text))
            result += " and StoreRoomId='" + extcomb_STOREROOM_ID.SelectedItem.Value + "' ";
        if (!string.IsNullOrEmpty(extcomb_SupplyId.SelectedItem.Text))
            result += " and SupplyId='" + extcomb_SupplyId.SelectedItem.Value + "' ";
        if (exttxtf_CargoName.Text.Trim() != "")
            result += " and CargoName like'%" + FilterSpecChar(exttxtf_CargoName.Text.Trim()) + "%'";
        if (exttxtf_Spec.Text.Trim() != "")
            result += " and Spec like'%" + FilterSpecChar(exttxtf_Spec.Text.Trim()) + "%'";
        if (exttxtf_Version.Text.Trim() != "")
            result += " and Version like'%" + FilterSpecChar(exttxtf_Version.Text.Trim()) + "%'";
        if (exttxtf_ProduceName.Text.Trim() != "")
            result += " and ProduceName like'%" + FilterSpecChar(exttxtf_ProduceName.Text.Trim()) + "%'";
        if (exttxtf_Area.Text.Trim() != "")
            result += " and Area like'%" + FilterSpecChar(exttxtf_Area.Text.Trim()) + "%'";
        if (exttxtf_CargoCode.Text.Trim() != "")
            result += " and CargoCode like'%" + FilterSpecChar(exttxtf_CargoCode.Text.Trim()) + "%'";
        if (exttxtf_BatchNo.Text.Trim() != "")
            result += " and BatchNo like'%" + FilterSpecChar(exttxtf_BatchNo.Text.Trim()) + "%'";

        return result;
    }

    protected void MyData_Refresh(object sender, StoreRefreshDataEventArgs e)
    {
        _QueryString = GetQryString();
        int count = CRMMis.BLL.ERP_ExportDetail.QueryInStoreDatilRecorderCount(_QueryString);
        BindGridPSData(e, ViewState_OrderSre, PagingToolbar1, Store1, count);
    }

    public override DataTable GetPSData(int PageSize, int CurPage, string OrderStr)
    {
        ViewState_OrderSre = OrderStr;
        DataTable dt = CRMMis.BLL.ERP_ExportDetail.QueryInStoreDatil(PageSize, CurPage, _QueryString, OrderStr);
        return dt;
    }

    protected void StoreSupply_Refresh(object sender, StoreRefreshDataEventArgs e)
    {
        var qStr = GetSupplyQryString();
        int recordcount = CRMMis.BLL.ERP_Supply.GetRecorderCount(qStr);
        int PageSize = extcomb_SupplyId.PageSize;
        int CurPage = e.Start / PageSize + 1;
        e.Total = recordcount;
        DataTable suppData = CRMMis.BLL.ERP_Supply.GetPageList(PageSize, CurPage, qStr, "SupplyName,Spell,Address").Tables[0];
        Store_Supply.DataSource = suppData;
        Store_Supply.DataBind();
    }

    private string GetSupplyQryString()
    {
        string StrSql = "DelState=0 ";
        string selText = FilterSpecChar(extcomb_SupplyId.SelectedItem.Text.Trim());
        if (!string.IsNullOrEmpty(selText))
            StrSql += " and ( SupplyName like '%" + selText + "%' or Spell like '%" + selText + "%') ";
        return StrSql;
    }


}